package com.ist.smartmonitor.server;

import com.ist.data.AbstractData;
import com.ist.data.Vehicle;
import com.ist.smartmonitor.server.notify.AbstractDataEvent;
import com.ist.smartmonitor.server.notify.VehicleUpdateEvent;
import com.ist.smartmonitor.server.notify.VehicleUpdateHandler;


public class UpdateObserver implements VehicleUpdateHandler{
	
	private AbstractData source = null;
	
	private static UpdateObserver instance = null;
	
	public static UpdateObserver getInstance() {
		if(instance == null) 
			instance = new UpdateObserver();
		return instance;
	}
	
	public AbstractData execute() throws Exception {
		System.out.println("EXECUTING");
		try {
			wait(50000);
			throw new Exception();
		} catch (InterruptedException e) {
			return source;
		}
	}

	@Override
	public void onAbstractDataEvent(AbstractDataEvent event) {
		source = (AbstractData) event.getSource();
		notify();
	}

	@Override
	public void onVehicleEvent(VehicleUpdateEvent event) {
		source = (Vehicle) event.getSource();
		notify();
	}
	
}
